package com.xnew.configuration;

import cn.hutool.core.util.StrUtil;
import com.auth0.jwt.JWT;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author yangcd
 * @Date 2020/10/14
 */
@Component
public class FeignTokenConfiguration {

    @Autowired
    private HttpServletRequest httpServletRequest;

    public String getAuthorization(){
        String authorization = httpServletRequest.getHeader("ebtc-authorization");

        /**
         * TODO
         * 目前的环境下可以不打开jwt校验
         *         Algorithm algorithm = Algorithm.HMAC256("000000");
         *         JWTVerifier verifier = JWT.require(algorithm)
         *                 .withIssuer("ebtc123")
         *                 .build();
         *         DecodedJWT jwt = verifier.verify(authorization);
         */
        if(StrUtil.isNotEmpty(authorization)){
            return JWT.decode(authorization).getAudience().get(0);
        }
        return "yangcd";
    }
}
